package com.sinosoft.perfect.system._roleSystem.dataFormat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sinosoft.perfect.common.xmlService.XmlInfoBean;
import com.sinosoft.perfect.common.xmlService.XmlProducerDom4j;
import com.sinosoft.perfect.system._.po.TRoleSystem;

public class RoleSystemGridDataFormat_DHX implements IRoleSystemGridDataFormat {

	@Override
	public String dataFormatRoleSystemGrid(List<TRoleSystem> roleSystemList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (roleSystemList != null && roleSystemList.size() > 0) {
			for (int i = 0; i < roleSystemList.size(); i++) {
				TRoleSystem roleSystem = roleSystemList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(roleSystem.getRoleSystemId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", roleSystem.getRoleSystemId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(roleSystem.getRoleSystemId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(roleSystem.getRoleSystemId());
				cell2.setContent(roleSystem.getRoleSystemName());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(roleSystem.getRoleSystemId());
				cell3.setContent(roleSystem.getNote());
				infos.add(cell3);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	@Override
	public String dataFormatRoleSystemGridForResource(List<TRoleSystem> roleSystemList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (roleSystemList != null && roleSystemList.size() > 0) {
			for (int i = 0; i < roleSystemList.size(); i++) {
				TRoleSystem roleSystem = roleSystemList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(roleSystem.getRoleSystemId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", roleSystem.getRoleSystemId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(roleSystem.getRoleSystemId());
				cell1.setContent(roleSystem.getRoleSystemName());
				infos.add(cell1);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	@Override
	public String dataFormatRoleSystemGridForBindUser(List<TRoleSystem> roleSystemList, List<String> roleSystemIds) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (roleSystemList != null && roleSystemList.size() > 0) {
			for (int i = 0; i < roleSystemList.size(); i++) {
				TRoleSystem roleSystem = roleSystemList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(roleSystem.getRoleSystemId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", roleSystem.getRoleSystemId());
				if (roleSystemIds != null && roleSystemIds.size() > 0) {
					for (int j = 0; j < roleSystemIds.size(); j++) {
						if (roleSystem.getRoleSystemId().equals(roleSystemIds.get(j))) {
							properties.put("select", "true");
						}
					}
				}
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(roleSystem.getRoleSystemId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(roleSystem.getRoleSystemId());
				cell2.setContent(roleSystem.getRoleSystemName());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(roleSystem.getRoleSystemId());
				cell3.setContent(roleSystem.getNote());
				infos.add(cell3);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}
	
	@Override
	public String roleSystemGridForBindAUnitUsers(List<TRoleSystem> roleSystemList, List<String> roleSystemIds) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (roleSystemList != null && roleSystemList.size() > 0) {
			for (int i = 0; i < roleSystemList.size(); i++) {
				TRoleSystem roleSystem = roleSystemList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(roleSystem.getRoleSystemId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", roleSystem.getRoleSystemId());
				if (roleSystemIds != null && roleSystemIds.size() > 0) {
					for (int j = 0; j < roleSystemIds.size(); j++) {
						if (roleSystem.getRoleSystemId().equals(roleSystemIds.get(j))) {
							properties.put("select", "true");
						}
					}
				}
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(roleSystem.getRoleSystemId());
				cell1.setContent(roleSystem.getRoleSystemName());
				infos.add(cell1);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}
	
	@Override
	public String roleSystemGridForBindAUnit(List<TRoleSystem> roleSystemList, List<String> roleSystemIds) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (roleSystemList != null && roleSystemList.size() > 0) {
			for (int i = 0; i < roleSystemList.size(); i++) {
				TRoleSystem roleSystem = roleSystemList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(roleSystem.getRoleSystemId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", roleSystem.getRoleSystemId());
				if (roleSystemIds != null && roleSystemIds.size() > 0) {
					for (int j = 0; j < roleSystemIds.size(); j++) {
						if (roleSystem.getRoleSystemId().equals(roleSystemIds.get(j))) {
							properties.put("select", "true");
						}
					}
				}
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(roleSystem.getRoleSystemId());
				cell1.setContent(roleSystem.getRoleSystemName());
				infos.add(cell1);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

}
